|
|
|
|
|
|
|
Puzzle 28
Drawing OLE Objects |
|
|
|
|
|
|
|
|
When I saw OLE 2.0 for the first time, I thought it was the most complicated technology I had ever seen from Microsoft. Then I chatted with a Microsoft developer. He explained that it was probably the most complicated technology yet to come from Microsoft. Now that I've been working with it for a few years, and it's called COM and ActiveX instead of OLE, I've come to realize that it is probably the most complicated technology Microsoft has ever shipped. |
|
|
|
|
|
|
|
|
So I won't even begin to try to teach OLE programming from Visual Basic in this book. Puzzles 25, 26, and 27 have hopefully given you a taste. (You can learn a lot about the concepts of COM and OLE from my book Developing COM/ActiveX Components with Visual Basic 6.0. Without some familiarity with COM, you will find this puzzle difficult, if not incomprehensible.) |
|
|
|
|
|
|
|
|
I've mentioned in several places that OLE does understand array and VB strings (BSTRs) and array parameters (SAFEARRAY). But the truth is, you will almost never run into those situations, because virtually all of the OLE functions that use these parameters duplicate functionality already provided in Visual Basic itself. |
|
|
|
|
|
|
|
|
But there is one type of parameter that OLE functions understand that you will need to use extensively if you start using the OLE API: objects. |
|
|
|
|
|
|
|
|
Displaying and Drawing Controls |
|
|
|
|
|
|
|
|
Have you ever wanted to print out the contents of a single control? Or print or display the contents of a control that is not actually visible? Visual Basic doesn't really provide a good way to do this. You can draw or print the contents of a control by displaying it and copying the bitmap, but stretching small bitmaps to a printer usually results in poor image quality, especially for text. And it's frustrating to have to display the control before printing it. |
|
|
|
|
|
|
|
|
Well, it turns out that ActiveX controls have to support an interface called IViewObject or IViewObject2. This interface describes a standard set of functions that allows an object to draw itself onto a device context (which can belong to a window or a printer). If only there was a way to directly use the IViewObject interface to force a control to draw its contents onto a device context, you would be able to display invisible controls or those that are not fully visible. You would be able to print them as well. |
|
|
|
|
|